package com.tgpms.web.pipenet.service.impl;

import com.tgpms.web.pipenet.entity.AppInMaterials;
import com.tgpms.web.pipenet.dao.AppInMaterialsMapper;
import com.tgpms.web.pipenet.service.IAppInMaterialsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.io.Serializable;
import java.util.UUID;
import java.time.LocalDateTime;
import com.tgpms.common.Result;
import com.tgpms.exception.ExceptionExplain;
import com.tgpms.util.Common;

/**
 * <p>
 * 管网app 材料表 服务实现类
 * </p>
 *
 * @author newway
 * @since 2020-10-30
 */
@Service
@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, rollbackFor = Exception.class)
public class AppInMaterialsServiceImpl implements IAppInMaterialsService {

	@Autowired
	private AppInMaterialsMapper iAppInMaterialsMapper;
	
	/**
		新增管网app 材料表
	*/
	@Override
	public Result<String> addAppInMaterials(AppInMaterials en) {
		String id = Common.nowTimeFomat("yyyyMMddHHmmss")+UUID.randomUUID().toString().replaceAll("-", "");
		en.setId(id);
		//en.setRowstamp(id);
		en.setInsertDate(LocalDateTime.now());
		int i = iAppInMaterialsMapper.insert(en);
		if(i==1) {
			return Result.OK(ExceptionExplain.SUCCESS_BY_INSERT.getExplain(), id);
		}else {
			return Result.ERROR(ExceptionExplain.ERROR_BY_INSERT.getExplain());
		}
	}
	
	/**
		更新管网app 材料表
	*/
	@Override
	public Result<String> updateAppInMaterials(AppInMaterials en) {
		int i = iAppInMaterialsMapper.updateById(en);
		if(i==1) {
			return Result.OK(ExceptionExplain.SUCCESS_BY_UPDATE.getExplain());
		}else {
			return Result.ERROR(ExceptionExplain.ERROR_BY_UPDATE.getExplain());
		}
	}
	
	/**
		根据主键删除管网app 材料表
	*/
	@Override
	public Result<String> deleteAppInMaterials(Serializable id) {
		int i = iAppInMaterialsMapper.deleteById(id);
		if(i==1) {
			return Result.OK(ExceptionExplain.SUCCESS_BY_DELETE.getExplain());
		}else {
			return Result.ERROR(ExceptionExplain.ERROR_BY_DELETE.getExplain());
		}
	}
}
